

package com.huaweicloud.haydn.delivercore.agent.config.log;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.pattern.CompositeConverter;

import org.apache.logging.log4j.util.Strings;

/**
 * @since 2022-09-24
 */
public class CleanLogInjectConverter extends CompositeConverter<ILoggingEvent> {

    @Override
    protected String transform(ILoggingEvent event, String in) {
        if (Strings.isEmpty(in)) {
            return in;
        }
        return in.replace("\n", "\\n")
            .replace("\r", "\\r")
            .replace("\f", "\\f")
            .replace("\b", "\\b")
            .replace("\u0007f", "\\u0007f");
    }

    @Override
    public void start() {
        started = true;
    }
}
